unit UfrmKernel_Pesquisa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UfrmKernel_Base, cxStyles, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinPumpkin, dxSkinSeven, dxSkinSharp, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ImgList,
  ActnList, RzStatus, RzPanel, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, dxGDIPlusClasses, ExtCtrls, StdCtrls, RzButton, cxLookAndFeels,
  cxLookAndFeelPainters,  JvExComCtrls, JvDateTimePicker;

type
  TfrmKernel_Pesquisa = class(TfrmKernel_Base)
    pnlTitulo: TRzPanel;
    lblSubtitulo: TLabel;
    lblTitulo: TLabel;
    imgCadBase: TImage;
    cxgrdPesquisa: TcxGrid;
    grdbtblvwPesquisa: TcxGridDBTableView;
    grdlvlPesquisa: TcxGridLevel;
    pnlFiltros: TRzPanel;
    rzstsbrbase: TRzStatusBar;
    RzStatusPane1: TRzStatusPane;
    actlstPesquisa: TActionList;
    ilPesquisa: TImageList;
    dsPesquisa: TDataSource;
    actlstUser: TActionList;
    ilUser: TImageList;
    pnlLegenda: TRzPanel;
    actFiltrar: TAction;
    actFechar: TAction;
    RzToolbar1: TRzToolbar;
    btnFiltrar: TRzToolButton;
    RzSpacer1: TRzSpacer;
    btnFechar: TRzToolButton;
    procedure actFiltrarExecute(Sender: TObject);
    procedure actFecharExecute(Sender: TObject);
    procedure grdbtblvwPesquisaDblClick(Sender: TObject);
    procedure grdbtblvwPesquisaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    // Pesquisa do produto registros conforme os parametros informados
    procedure PesquisaBase; virtual;
    procedure Antes_PesquisaBase; virtual;
    procedure Depois_PesquisaBase; virtual;
    procedure Executa_PesquisaBase; virtual;

    // Inseri o registro selecionado no grid na tabela informada no filho
    procedure InseriBase; virtual;
    // Abre um a Tela de cadastrar novo produto[SC]
    procedure Kernel_Abre_Cadasto; virtual;

    function AnalisaPodePesquisa(): Boolean; virtual;

    procedure Inseri_Novo_Registro; virtual;
  end;

var
  frmKernel_Pesquisa: TfrmKernel_Pesquisa;

implementation

uses UfrmKernel_Aguarde;

{$R *.dfm}

{ TfrmKernel_Pesquisa }

procedure TfrmKernel_Pesquisa.actFecharExecute(Sender: TObject);
begin
  inherited;
  close;
end;

procedure TfrmKernel_Pesquisa.actFiltrarExecute(Sender: TObject);
begin
  inherited;
  Executa_PesquisaBase;
end;

function TfrmKernel_Pesquisa.AnalisaPodePesquisa: Boolean;
Var
  i : Integer;
Begin
  Result := False;

  for i := 0 to ComponentCount -1 do
  Begin
    if Components[i] is TEdit then
      begin
       if TEdit(Components[i]).Text <> '' then
         begin
           Result := True;
         end;
      end;

    if Components[i] is TComboBox then
      begin
       if TComboBox(Components[i]).Text <> '' then
         begin
           Result := True;
         end;
      end;

    if Components[i] is TJvDateTimePicker then
      Result := True;
  End;

end;

procedure TfrmKernel_Pesquisa.Antes_PesquisaBase;
begin

end;

procedure TfrmKernel_Pesquisa.Depois_PesquisaBase;
begin

end;

procedure TfrmKernel_Pesquisa.Executa_PesquisaBase;
begin
  if AnalisaPodePesquisa then
    Begin
      if not Assigned(frmKernel_Aguarde) then
        Application.CreateForm(TfrmKernel_Aguarde, frmKernel_Aguarde);
      try
        frmKernel_Aguarde.Show;
        frmKernel_Aguarde.Update;
        Application.ProcessMessages;

        PesquisaBase;

      finally
        if Assigned(frmKernel_Aguarde) then
          FreeAndNil(frmKernel_aguarde);
      end;
    End;

end;

procedure TfrmKernel_Pesquisa.grdbtblvwPesquisaDblClick(Sender: TObject);
begin
  inherited;
  // Se de dois cliques inseri itm
  if not (dsPesquisa.DataSet.IsEmpty) then
    InseriBase;
end;

procedure TfrmKernel_Pesquisa.grdbtblvwPesquisaKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  // Se for Enter [SC]
  case key of
    VK_RETURN : Begin
                  // Verifica se tem registros [SC]
                  if not (dsPesquisa.DataSet.IsEmpty) then
                    InseriBase;
                End;

    VK_INSERT : Kernel_Abre_Cadasto;
    VK_Escape : close;
  end;
end;

procedure TfrmKernel_Pesquisa.InseriBase;
begin

end;

procedure TfrmKernel_Pesquisa.Inseri_Novo_Registro;
begin

end;

procedure TfrmKernel_Pesquisa.Kernel_Abre_Cadasto;
begin

end;

procedure TfrmKernel_Pesquisa.PesquisaBase;
begin

end;

end.
